GM.Name 	= "Incursion"
GM.Author 	= "RabidToaster and Devenger"
GM.Email 	= ""
GM.Website 	= "http://incursion.rabidtoaster.com"

-- Useful for debugging.
local printd_players = {}
function printd( ... )
	if ( GetConVarNumber( "developer" ) == 0 ) then return end
	
	local s = ""
	
	// Gets the filename of the function calling printd, and strips it down to lastfolder/filename.
	local info = debug.getinfo(2, "S")
	if info.short_src then
		local found = false
		for p = string.len(info.short_src), 1, -1 do
			local c = string.sub(info.short_src, p, p)
			if c == "\\" || c == "/" then
				if found then
					s = string.sub(info.short_src, p + 1) .. ":  "
					break
				end
				found = true
			end
		end
	end
	
	for _, v in ipairs({...}) do
		s = s .. tostring(v) .. " "
	end
	s = string.sub(s, 1, -2) // Take off the last space.
	
	MsgN(s)

	if SERVER then
		for ply, _ in pairs(printd_players) do
			if IsValid(ply) then
				ply.printd_buffer = ply.printd_buffer .. s .. "\n"
			end
		end
	end
end

if SERVER then
	util.AddNetworkString("printd")
	local function printd_transmit()
		for ply, _ in pairs(printd_players) do
			if ply.printd_buffer and string.len(ply.printd_buffer) > 0 then
				net.Start("printd")
					net.WriteString(ply.printd_buffer)
				net.Send(ply)

				ply.printd_buffer = ""
			end
		end
	end

	concommand.Add("printd", function(ply)
		if !ply:IsSuperAdmin() then return end
		ply.printd_buffer = ""
		printd_players[ply] = true

		timer.Create("printd_transmit", 0.5, 0, printd_transmit)
	end)
end
if CLIENT then
	local SERVER_color = Color(137, 222, 255)
	local function printd_receive()
		local text = net.ReadString()
		MsgC(SERVER_color, text)
	end
	net.Receive("printd", printd_receive)
end


-- Useful for base GM values.
function Default( name, val )
	local g = GM or GAMEMODE
	g[ name ] = g[ name ] or val
end

-- Structure file.
include( "structure.lua" )

function GM:PlayerNoClip(ply, on)
	return !on or ply:IsSuperAdmin()
end